﻿Public Class frmMoniteursSEMD
    Public pNoLigne As Integer
    Public pCD_MON As String
    Public pDateTime As Date

    Private szSQL As String
    Private rs As ADODB.Recordset

    Private Sub frmMoniteursSEMD_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        RdVToScreen()

    End Sub

    Private Sub RdVToScreen()

        If pNoLigne = 0 Then
            ClearTextBoxes(Me)
            TE_QTE.Value = 1
            TE_DATETIME.Value = pDateTime.Date
            TE_DATETIME.Value = TE_DATETIME.Value.AddHours(pDateTime.Hour)
        Else
            ' Lire le rendez-vous sélectionné
            szSQL = "CALL spGet_MONITEURS_SEMAINE(" & pNoLigne & ")"
            GetRecordset(ctDSN_AEM, szSQL, rs)
            If rs.RecordCount > 0 Then
                TE_ACTIVITE.Text = rs.Fields("activite").Value
                gCD_CLI = TE_ACTIVITE.Text
                TE_DATETIME.Value = rs.Fields("dh_debut").Value
                TE_QTE.Value = rs.Fields("qte").Value
                TE_INTITULE.Text = nv(rs.Fields("intitule").Value)
                TE_MODIFIE_LE.Text = setModifiedBy(rs.Fields("cree_le").Value, rs.Fields("modif_le").Value, rs.Fields("cd_uti").Value)
            End If
            rs.Close()
        End If
        Me.Text = "SEMAINE - " & pCD_MON & " - " & TE_DATETIME.Text
    End Sub

    Private Sub BO_RECHERCHER_Click(sender As System.Object, e As System.EventArgs) Handles BO_RECHERCHER.Click

        ' si Elève provisoire, proposer le dernier code client consulté
        If TE_ACTIVITE.TextLength Then
            gCD_CLI = TE_ACTIVITE.Text
        End If
        ' ouvre la fenetre de Recherche ELEVES
        frmElevesSearch.pType = "ACTIV"
        frmElevesSearch.ShowDialog()

        ' le nouveau doit être une activité
        If gCD_CLI > 100000 Then
            MsgBox("Vous devez sélectionner une activité !", MsgBoxStyle.Critical)
            Exit Sub
        End If
        TE_ACTIVITE.Text = gCD_CLI
        TE_INTITULE.Text = frmElevesSearch.Nompren

    End Sub

    Private Sub BO_ENREGISTRER_Click(sender As Object, e As System.EventArgs) Handles BO_ENREGISTRER.Click

        ' mise à jour le rdv
        szSQL = "CALL spUpd_MONITEURS_SEMAINE(" & pNoLigne & "," & TE_ACTIVITE.Text & ",'" & TE_INTITULE.Text & "','" & Format(TE_DATETIME.Value, "yyyy/MM/dd HH:mm") & "'," & _
                 TE_QTE.Value & ",'" & pCD_MON & "'," & gUserAgence & ",'" & gUserCode & "')"
        ExecQuery(ctDSN_AEM, szSQL)
        Me.Close()

    End Sub
End Class